﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ESRI.ArcGIS.SystemUI;

namespace CanSWAT.Util
{
    partial class ExecuteArcMapCommandsFrm : Form
    {
        private SortedDictionary<string, ICommand> _commands;

        public ExecuteArcMapCommandsFrm(SortedDictionary<string, ICommand> cmds)
        {
            InitializeComponent();

            _commands = cmds;
        }

        private void ExecuteArcMapCommandsFrm_Load(object sender, EventArgs e)
        {
            foreach (ICommand cmd in _commands.Values)
            {
                TreeNode node = null;
                if (treeView1.Nodes.ContainsKey(cmd.Category))
                    node = treeView1.Nodes[cmd.Category];
                else
                    node = treeView1.Nodes.Add(cmd.Category, cmd.Caption);

                node.Nodes.Add(cmd.Caption);
            }
        }

        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            if (_commands.ContainsKey(e.Node.Text))
                _commands[e.Node.Text].OnClick();
        }
    }
}
